<?php
class CategoryModel extends Model{
	public $validate=array(
		array('cname','nonull','栏目名不能为空',2,3)
	);
	public $table ='category';
	public function add_category(){
		if($this->create()){
			if($this->add()){
				return $this->update_cache();
			}
		}
	}
	public function edit_category(){
		if($this->create()){
			if($this->save()){
				return $this->update_cache();
			}
		}
	}
	public function del_category(){
		$cid=Q("cid");
		if($this->where('pid='.$cid)->find()){
			$this->error="请先删除子栏目";
		}else{
			if($this->del($cid)){
				return $this->update_cache();
			}
		}
	}
	public function update_cache(){
		$category=Data::tree($this->all(),'cname');
		return F("category",$category);
	}
}